<?php
/**
 *
 */
class Sx_htmlupload extends CI_Controller {

	public function index($w = NULL, $h= NULL,$pc=FALSE) {
		!isset($w) || empty($w) ? $w = 100 : $w;
		!isset($h) || empty($h) ? $h = 100 : $h;
		$IMG = "";
		$thumb_IMG = "";
		$p = BASEPATH;
		$p = substr($p, 0, -7);
		$config['upload_path'] = $p . 'upload/big/';
		$config['allowed_types'] = 'gif|jpg|png';
		$config['encrypt_name'] = TRUE;
		$config['max_size'] = '1000';
		$this -> load -> library("upload", $config);
		if (!$this -> upload -> do_upload("hck_img")) {
			echo $this -> upload -> display_errors();
		} else {			
			$IMGArr = $this -> upload -> data();
			$IMG = $IMGArr['full_path'];
			$config['image_library'] = 'gd2';
			$config['source_image'] = $IMG;
			$config['create_thumb'] = TRUE;
			$config['maintain_ratio'] = TRUE;
			$config['new_image'] = $p . "upload/thumb/";
			$config['width'] = $w;
			$config['height'] = $h;
			$this -> load -> library('image_lib', $config);
			if (!$this -> image_lib -> resize()) {
				echo $this -> image_lib -> display_errors();
			}else{
				header("Content-Type:text/html; charset=utf-8");
				$rArr = array('Msg_error' => "0", 'Msg' => "上传成功", 'MsgTime' => date("Y-m-d H:i:s"));
				$rArr['thumb']=base_url()."upload/thumb/".$IMGArr["raw_name"]."_thumb".$IMGArr["file_ext"];
				$rArr['big'] = base_url()."upload/big/".$IMGArr["file_name"];
				if($pc){
					print("<div id='pic_path'>");
					print(base_url()."upload/big/".$IMGArr["file_name"]);
					print("<script> window.opener.document.getElementById('pic_path').value= '".base_url()."upload/big/".$IMGArr["file_name"]."';window.close();</script>");
					print("</div>");
				}else{
					print(json_encode($rArr));
				}
				
			}

		}
	}

}
?>